/**
 * 
 */
package com.meiwenhui.sishuwujing.adapter;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.meiwenhui.sishuwujing.R;
import com.meiwenhui.sishuwujing.entities.Book;

/**
 * @file BooksAdapter.java
 * @author linbin
 * @email linbin.java@gmail.com
 * @date 2013-1-4
 * @description
 */
public class BooksAdapter extends BaseAdapter {

	private Context context;
	private List<Book> books;
	private LayoutInflater inflater;

	/**
	 * @param context
	 * @param books
	 */
	public BooksAdapter(Context context, List<Book> books) {
		super();
		this.context = context;
		this.books = books;
		inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see android.widget.Adapter#getCount()
	 */
	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return books.size();
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see android.widget.Adapter#getItem(int)
	 */
	@Override
	public Object getItem(int i) {
		// TODO Auto-generated method stub
		return books.get(i);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see android.widget.Adapter#getItemId(int)
	 */
	@Override
	public long getItemId(int i) {
		// TODO Auto-generated method stub
		return i;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see android.widget.Adapter#getView(int, android.view.View,
	 * android.view.ViewGroup)
	 */
	@Override
	public View getView(int i, View view, ViewGroup viewgroup) {
		TextView textView = null;
		Book book = books.get(i);
		if (view == null) {
			view = inflater.inflate(R.layout.activity_main_gridview_item, null);
		}
		textView = (TextView) view.findViewById(R.id.amgi);
		textView.setText(book.getName());
		textView.setTag(book);
		return textView;
	}

}
